package com.ruoyi.service.production.impl;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.production.MesWorkOrder;
import com.ruoyi.mapper.production.MesWorkOrderMapper;
import com.ruoyi.service.production.IMesWorkOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 生产工单Service业务层处理
 * 
 * @author ruoyi
 */
@Service
public class MesWorkOrderServiceImpl implements IMesWorkOrderService
{
    @Autowired
    private MesWorkOrderMapper mesWorkOrderMapper;

    /**
     * 查询生产工单
     * 
     * @param orderId 生产工单主键
     * @return 生产工单
     */
    @Override
    public MesWorkOrder selectMesWorkOrderByOrderId(Long orderId)
    {
        return mesWorkOrderMapper.selectMesWorkOrderByOrderId(orderId);
    }

    /**
     * 查询生产工单列表
     * 
     * @param mesWorkOrder 生产工单
     * @return 生产工单
     */
    @Override
    public List<MesWorkOrder> selectMesWorkOrderList(MesWorkOrder mesWorkOrder)
    {
        return mesWorkOrderMapper.selectMesWorkOrderList(mesWorkOrder);
    }

    /**
     * 校验工单编号是否唯一
     * 
     * @param orderCode 工单编号
     * @return 结果
     */
    @Override
    public boolean checkOrderCodeUnique(String orderCode, Long orderId)
    {
        if (StringUtils.isEmpty(orderCode))
        {
            return false;
        }
        MesWorkOrder workOrder = mesWorkOrderMapper.checkOrderCodeUnique(orderCode, orderId);
        return workOrder == null;
    }

    /**
     * 根据计划ID查询工单列表
     * 
     * @param planId 计划ID
     * @return 工单集合
     */
    @Override
    public List<MesWorkOrder> selectMesWorkOrderListByPlanId(Long planId)
    {
        return mesWorkOrderMapper.selectMesWorkOrderListByPlanId(planId);
    }

    /**
     * 新增生产工单
     * 
     * @param mesWorkOrder 生产工单
     * @return 结果
     */
    @Override
    public int insertMesWorkOrder(MesWorkOrder mesWorkOrder)
    {
        return mesWorkOrderMapper.insertMesWorkOrder(mesWorkOrder);
    }

    /**
     * 修改生产工单
     * 
     * @param mesWorkOrder 生产工单
     * @return 结果
     */
    @Override
    public int updateMesWorkOrder(MesWorkOrder mesWorkOrder)
    {
        return mesWorkOrderMapper.updateMesWorkOrder(mesWorkOrder);
    }

    /**
     * 批量删除生产工单
     * 
     * @param orderIds 需要删除的生产工单主键
     * @return 结果
     */
    @Override
    public int deleteMesWorkOrderByOrderIds(Long[] orderIds)
    {
        return mesWorkOrderMapper.deleteMesWorkOrderByOrderIds(orderIds);
    }

    /**
     * 删除生产工单信息
     * 
     * @param orderId 生产工单主键
     * @return 结果
     */
    @Override
    public int deleteMesWorkOrderByOrderId(Long orderId)
    {
        return mesWorkOrderMapper.deleteMesWorkOrderByOrderId(orderId);
    }
}